// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import RankItem from "./item/RankItem";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    private _view: fgui.GComponent;
    private _list: fgui.GList;

    onLoad() {
        fgui.addLoadHandler();

        fgui.GRoot.create();
        // window.share

        fgui.UIPackage.loadPackage("UI/IMGame", this.onUILoaded.bind(this));
    }

    onUILoaded() {
        // fgui.UIObjectFactory.setExtension("ui://IMGame/RankItem", RankItem);
        // fgui.UIObjectFactory.setExtension("ui://IMGame/RankItem", RankItem);
        
        this._view = fgui.UIPackage.createObject("IMGame", "WechatRankPanel").asCom;
        this._view.makeFullScreen();
        fgui.GRoot.inst.addChild(this._view);

        this._view.getChild("n1").onClick(this.onBack,this);
        // this._view.getChild("n7").onClick(function (): void { this._list.scrollPane.scrollTop(); }, this);
        // this._view.getChild("n8").onClick(function (): void { this._list.scrollPane.scrollBottom(); }, this);

        this._list = this._view.getChild("n7").asList;
        this._list.setVirtual();

        this._list.itemProvider=this.getitemResource.bind(this);
        this._list.itemRenderer = this.renderListItem.bind(this);
        this._list.numItems = 1000;
    }

    onBack(){
       cc.director.loadScene("start"); 
    }

    getitemResource(index: number):string{
        return "ui://IMGame/RankItem";
    }

    private renderListItem(index: number, obj: fgui.GButton): void {
        var item: RankItem = <RankItem>obj;
       
        item.title = index + " Mail title here";
    }
}
